import Rx from "rxjs"

// typing "hello world"
var input = Rx.Observable.fromEvent(document.querySelector('#myInput'), 'input');

// Pass on a new value
// input.map(event => event.target.value)
//   .subscribe(value => console.log(value)); // "h"

// Pass on a new value by plucking it
// input.pluck('target', 'value')
//   .subscribe(value => console.log(value)); // "h"

// Pass the two previous values
// input.pluck('target', 'value').pairwise()
//   .subscribe(value => console.log(value)); // ["h", "e"]

//scan测试
// var button = document.querySelector('button');
// Rx.Observable.fromEvent(button, 'click')
//     // scan (reduce) to a stream of counts 对输入的值按照时间维度进行统计，起始值为0
//     .scan(count => count + 1, 0)
//     // Set the count on an element each time it changes
//     .subscribe(
//     count => { document.querySelector('#count').innerHTML = count }
//     );


var increaseButton = document.querySelector('#increase');
var increase = Rx.Observable.fromEvent(increaseButton, 'click')
    // We map to a function that will change our state
    .map(() => {
        state => { 
            Object.assign({}, state, { count: state.count + 1 }) 
        }
    });